<?php

class Lib_FlashSMS_Adapter
{
    public static $error_message = [];
    private static $obj_arr = array();

    public static function create($pass)
    {
        if (!array_key_exists($pass, self::$obj_arr) || is_null(self::$obj_arr[$pass])) {
            $class_name = 'Lib_FlashSMS_Adapter_' . ucfirst($pass);

            if (!class_exists($class_name)) {
                throw new Exception('sms pass configuration error!', 4004);
            }
            self::$obj_arr[$pass] = new $class_name();
        }
        return self::$obj_arr[$pass];
    }

    public static function getAdapter($pass)
    {
        $pass = trim($pass);
        $conf_pass = Lib_FlashSMS_Config::get_pass($pass);
        if (empty($conf_pass)) {
            throw new Exception('sms pass account configuration error!', 4003);
        }
        $pass_obj = self::create($pass);
        $pass_obj->setConfig($conf_pass);

        return $pass_obj;
    }


}